package com.itlong.cloud.commons.wechat;


import com.itlong.cloud.iottp.IWeChatMessageServiceClient;
import com.itlong.cloud.paymenthub.IWeChatPayServiceClient;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

/**
 * <desc>
 *      微信自动关联公众号与小程序的openid关联关系
 * </desc>
 *
 * @createDate 2018/08/18
 */
@EnableScheduling // 启用定时任务
@RestController
public class WechatUpdateOfficeOpenIdAndMiniProgramTask {
    private static Logger LOG = LoggerFactory.getLogger(WechatUpdateOfficeOpenIdAndMiniProgramTask.class);

    @Autowired
    IWeChatMessageServiceClient iWeChatMessageServiceClient;

    /**
     * <desc>
     *      定时任务获取前一天的微信对账单
     * </desc>
     *
     * @throws Exception
     * @author Juguang.S
     * @createDate 2018/09/03
     */
    @Scheduled(cron = "0 0/5 * * * ?") // 每小时执行一次
    public void statisticsForDay() throws Exception {
        Thread thread = new Thread(){
            public void run(){
                try {
                    iWeChatMessageServiceClient.bindOfficeOpenIdAndMiniProgramOpenId();
                } catch (Exception e) {
                    LOG.error("【定时任务】微信自动关联公众号与小程序的openid关联关系失败");
                }
            }
        };
        thread.start();
//        LOG.info("【定时任务】微信自动关联公众号与小程序的openid关联关系成功");
    }
}